package com.lazy.book.service.system.impl;

import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.lazy.book.mapper.system.SysDataRoleMenuMapper;
import com.lazy.book.pojo.system.pojo.po.SysDataRoleMenu;
import com.lazy.book.service.system.SysDataRoleMenuService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author lay
 * @since 2025-09-05
 */
@Service
@RequiredArgsConstructor
public class SysDataRoleMenuServiceImpl extends ServiceImpl<SysDataRoleMenuMapper, SysDataRoleMenu> implements SysDataRoleMenuService {

    private final SysDataRoleMenuMapper sysDataRoleMenuMapper;

    @Override
    public void batchInsert(Long dataRoleId, List<Long> menuIds) {
        List<SysDataRoleMenu> list = menuIds.stream().map(menuId -> {
            SysDataRoleMenu sysDataRoleMenu = new SysDataRoleMenu();
            sysDataRoleMenu.setDataRoleId(dataRoleId);
            sysDataRoleMenu.setMenuId(menuId);
            return sysDataRoleMenu;
        }).collect(Collectors.toList());
        sysDataRoleMenuMapper.insertBatch(list);
    }

    @Override
    public List<String> getSelectMenuIdByRoleId(Long roleId) {
        QueryWrapper wrapper = QueryWrapper.create().select(SYS_DATA_ROLE_MENU.MENU_ID).where(SYS_DATA_ROLE_MENU.ROLE_ID.eq(roleId));
        return listAs(wrapper, String.class);
    }

}